package system

import (
	"atools/models"
	"atools/utils"
	"bytes"
	"os/exec"
	"strings"
)

type WindowsSystemInfo struct {
}

func (windows WindowsSystemInfo) GetInstalledApps(app *App) []models.InstalledApp {
	// 简化：列出 Program Files 中的部分目录
	directories := []string{
		"C:\\Program Files\\*",
		"C:\\Program Files (x86)\\*",
	}

	var apps []models.InstalledApp
	for _, dir := range directories {
		cmd := exec.Command("PowerShell", "-Command", "Get-ChildItem", dir, "|", "Where-Object { $_.PSIsContainer }", "|", "Select-Object -ExpandProperty Name")
		var out bytes.Buffer
		cmd.Stdout = &out
		err := cmd.Run()
		if err != nil {
			return nil
		}

		for _, name := range strings.Split(out.String(), "\n") {
			name = strings.TrimSpace(name)
			if name != "" {
				apps = append(apps, models.InstalledApp{
					Name:    name,
					EnName:  utils.GetPingYin(name),
					Path:    dir + "\\" + name,
					AppType: "InstallApp",
				})
			}
		}
	}
	return apps
}
